function showTab(tabid,number){
	tab=document.getElementById(tabid);	
	if(tab == null){
		return;
	}
	tabPanel=tabs_findParentNode(tab,'tab_panel');
	
	content=tabPanel.childNodes;
	for(i=0;i<content.length;i++){
		tabContent=content.item(i);
		if(tabContent.id=='tab_content'){		
			break;
		}
	}
	
	content=tabContent.getElementsByTagName("div");
	for(i=0,j=0;i<content.length;i++){
		element=content.item(i);
		if(j==number){
			tabScene=element;
		}
		if(element.className=='tab_scene'){
			element.style.display='none';			
			j++;
		}
	}	
	tabScene.style.display='block';
	


	tabHeader=tabs_findParentNode(tab,'tab_header');
	uList=tabHeader.getElementsByTagName("ul").item(0);	
	tabTitles=uList.getElementsByTagName("li");		
	for(i=0;i<tabTitles.length;i++){
		element=tabTitles.item(i);				
		if(element==tab.parentNode){
			element.id='selected';
		}else {
			element.id='';
		}		
	}
	
	var exdate=new Date();
	exdate.setMinutes(exdate.getMinutes()+2);
	document.cookie="TAB_ID="+escape(tabid)
		+";expires="+exdate.toGMTString()
		+"path="+location.pathname;
	document.cookie="TAB_NUMBER="+escape(number)
		+";expires="+exdate.toGMTString()
		+"path="+location.pathname;
}

function tabs_findParentNode(link,parent){	
	node=link.parentNode;
	if(node.id==parent){
		return node;
	}else if(node==document.body){
		return null;
	}else{
		return tabs_findParentNode(node,parent); 
	}		 
}

function getCookie(name) {
    var theCookies = document.cookie.split(/[; ]+/);
    for (var i = 0 ; i < theCookies.length; i++) {
        var aName = theCookies[i].substring(0,theCookies[i].indexOf('='));
        if (aName == name) {
            return theCookies[i].split(/[=]+/)[1];
        }
    }
}

function tab_restore_state(){
	tabid=getCookie("TAB_ID");
	number=getCookie("TAB_NUMBER");
	if(tabid!=null&&number!=null){
		showTab(tabid,number);
	}
}

window.onload=tab_restore_state;
